<?php
ob_start();
session_start();
include "checksession.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
		<link href="../images/it_service_logo.png" rel="shortcut icon" type="image/x-icon" />
        <link rel="stylesheet" href="../css/style.css"/>
        <script type="text/javascript" src="../js/jquery/jquery.js"></script>
        <script type="text/javascript" src="../js/jquery/jquery.validationEngine.js"></script>
        <link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css" />
        <!--<script language="javascript" src="../js/jquery/jquery-1.7.1.min"></script>-->
        <script type="text/javascript" src="../fancybox/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
        <script type="text/javascript" src="../fancybox/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
        <link rel="stylesheet" type="text/css" href="../fancybox/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
        <link rel="stylesheet" href="../fancybox/style.css" />

        <script type="text/javascript">
            $(document).ready(function() {
                $TtoolTipAjax();
            });
            $TtoolTipAjax = function() {//ทีทูลทิป ฟังก์ชั่น
                $('.lnk').hover(function(e) { //Mouse Hover แอทริบิวต์ คลาส ชื่อ lnk
                    $('body').append('<div class="showTooltip"> </div>');
                    var showTooltip = $('.showTooltip');
                    $.ajax({//เรียกใช้ ajax ของ jQuery
                        url: $(this).attr('turl') + '&' + new Date().getTime(),
                        beforeSend: function() {//ก่อนส่งค่า 
                            showTooltip.html('<img src="wait.gif"/>'); //แสดงตัว loading 
                        },
                        success: function(data) {//ส่งค่าเสร็จสมบูรณ์ พร้อมกับผลลัพธุ์ถูกส่งกลับมา(data)
                            showTooltip.html(data);
                        }
                    });
                    var mousex = e.pageX + 10;
                    var mousey = e.pageY;
                    var tooltipWidth = showTooltip.width();
                    var tooltipHeight = showTooltip.height();
                    var toolVisX = $(window).width() - (mousex + tooltipWidth);
                    var toolVisY = ($(window).height() + $(window).scrollTop()) - (mousey + tooltipHeight);
                    if (toolVisX < 10) {
                        mousex = e.pageX - tooltipWidth - 40;
                    }
                    if (toolVisY < 10) {
                        mousey = e.pageY - tooltipHeight - 10;
                    }
                    showTooltip.css({top: mousey, left: mousex, display: 'none'});
                    showTooltip.slideDown('slow');
                }, function() { //Mouse Out
                    $('.showTooltip').remove();//Remove Tooltip
                })
            }
        </script>

        <style type="text/css">
            /*ปรับสีสันของ Tooltip ได้จากคำสั่ง CSS ตรงนี้*/
            body{
                font-size:12px;
                font-family:Tahoma, Geneva, sans-serif;
            }
            .showTooltip{
                float:left;
                padding:10px;
                background:#F3F3F3;
                border:2px solid #CFCFCF;
                -moz-border-radius: 4px;  
                -webkit-border-radius: 4px;  
                border-radius: 4px;
                color:#333;
                position:absolute;
            }
            a{
                margin:5px;
                color:#06C;
                text-decoration:none;
            }
        </style>

        <script type="text/javascript">
            $(function() {
                var objSet = "#txtKeyword";
                var objSetText = "ค้นหาด้วย ชื่อ, ประเภท";
                if ($(objSet).val() == "") {
                    $(objSet).val(objSetText);
                }
                $(objSet).focus(function() {
                    if ($(objSet).val() == objSetText) {
                        $(objSet).val("");
                    }
                }).blur(function() {
                    if ($(objSet).val() == "") {
                        $(objSet).val(objSetText);
                    }
                });
            });
        </script>
        <script type="text/javascript">

            $(document).ready(function() {

                $("#addCom").fancybox({
                    'width': '100%',
                    'height': '100%',
                    'autoScale': true,
                    'scrolling': 'auto',
                    'transitionIn': 'elastic',
                    'transitionOut': 'none',
                    'type': 'iframe',
                    'overlayColor': '#000',
                    'hideOnOverlayClick': false,
                    onCleanup: function() {
                        return window.location.reload();
                    }
                });

                $('a[id^="edit"]').fancybox({
                    'width': '100%',
                    'height': '100%',
                    'autoScale': true,
                    'scrolling': 'auto',
                    'transitionIn': 'elastic',
                    'transitionOut': 'none',
                    'type': 'iframe',
                    'overlayColor': '#000',
                    'hideOnOverlayClick': false,
                    onClosed: function() {
                        parent.location.reload(true);
                    }
                });

                $('a[id^="delete"]').fancybox({
                    'width': '20%',
                    'height': '20%',
                    onStart: function() {
                        return window.confirm('คุณต้องการลบรายการนี้ไหม?');
                    },
                    onClosed: function() {
                        parent.location.reload(true);
                    }
                });
            });
        </script>
    </head>
    <body> 
        <body class="body">
            <table align="center" width="90%">
                <tr>
                    <td colspan="2" class="header" >
                        <img src="../images/logo.png"> <img src="../images/it_service_text.png" width ="150">
                            <hr/>
                    </td>
                </tr >

                <tr  valign="top">
                    <td class="left">
                        <?php include_once "left.php"; ?>
                    </td>
                    <td>
                        <div align="right">
                            <form id="searchperson" name="txtKeyword" method="get" action="searchManageTreasury.php">
                                <input name="txtKeyword" size="35" type="text" id="txtKeyword" class="validate[required]"/>
<!--                                <input type="hidden" name="hidOK">-->
                                <input type="image" name="search" id="search" value="submit" src="../images/search.png">
                            </form>

                        </div>
                        <?
                        include_once '../connect.php';


                        $strSQL = "SELECT * FROM product inner join prd_type on product.type_id = prd_type.type_id
                                            ";

                        $objQuery = mysql_query($strSQL) or die("Error Query [" . $strSQL . "]");
                        $Num_Rows = mysql_num_rows($objQuery);
                        $n = 1;
                        $Per_Page = 7;   // Per Page

                        $Page = $_GET["Page"];
                        if (!$_GET["Page"]) {
                            $Page = 1;
                        }

                        $Prev_Page = $Page - 1;
                        $Next_Page = $Page + 1;

                        $Page_Start = (($Per_Page * $Page) - $Per_Page);
                        if ($Num_Rows <= $Per_Page) {
                            $Num_Pages = 1;
                        } else if (($Num_Rows % $Per_Page) == 0) {
                            $Num_Pages = ($Num_Rows / $Per_Page);
                        } else {
                            $Num_Pages = ($Num_Rows / $Per_Page) + 1;
                            $Num_Pages = (int) $Num_Pages;
                        }

                        $strSQL .=" order  by prd_inDate DESC , prd_id  DESC LIMIT $Page_Start , $Per_Page";
                        $objQuery = mysql_query($strSQL);
                        ?>

                        <div align="right">
                            <a id="addCom" href="addManageTreasury.php">
                                <img src="../images/device_removable.png" width="40px" >
                            </a>

                        </div>
                        <div class="nameTitle">รายชื่ออุปกรณ์</div>
                        <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" class="simply">
                            <thead>
                                <tr>
                                    <th width="5%">ลำดับ</th> 

                                    <th width="10%">ชื่ออุปกรณ์</th>
                                    <th width="5%" align = "center">จำนวน</th>
                                    <th width="5%" align = "center">ยอดคงเหลือ</th>
                                    <th width="10%" align = "center">ประเภทอุปกรณ์</th>      
                                    <th width="5%" align = "center">วันที่</th>
                                    <th width="5%" align = "center">แก้ไข</th>
                                    <th width="5%" align = "center">รายละเอียด</th>
                                </tr>
                            </thead>
                            <?
                            $n = 1;
                            if ($Page > 1) {
                                $n = ($Per_Page * ($Page - 1)) + 1;
                            }
                            while ($objResult = mysql_fetch_array($objQuery)) {
                                $rsDate = $objResult['prd_inDate'];
                                $rsFoDate = date('d-m-Y', strtotime($rsDate));
                                ?>
                                <tbody>
                                    <tr>
                                        <td>  <?php echo $n++; ?></td>
                                        <td><a href="#" turl="showproductdetail.php?id=<?= $objResult["prd_id"] ?>" class="lnk"><?= $objResult["prd_name"] ?></a></td>
                                        <td align = "center"><?= $objResult["prd_amount"]; ?></td> 
                                        <td align = "center"><?= $objResult["prd_balance"]; ?></td>                                     	
                                        <td align = "center"><?= $objResult["type_name"]; ?></td>   
                                        <td align = "center"><?= $rsFoDate ?></td>
                                        <td align = "center"> <a id="edit<?= $n; ?>" href="editManageTreasury.php?id=<?= $objResult["prd_id"]; ?>">
                                                <img src="../images/write.png" width="35px" > </td>

                                                    <td align = "center"> <a href="ProductDe.php?prd_id=<?= $objResult["prd_id"]; ?>">
                                                            <img src="../images/order.png" width="35px" >
                                                        </a>
                                                    </td> 
                                                    </tr>
                                                    <?
                                                }
                                                ?>
                                                </tbody>
                                                </table>
                                                <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" class="simply">
                                                    <tr>
                                                        <td>
                                                            <br>
                                                                Total <?= $Num_Rows; ?> Record : <?= $Num_Pages; ?> Page :
                                                                <?
                                                                if ($Prev_Page) {
                                                                    echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
                                                                }

                                                                for ($i = 1; $i <= $Num_Pages; $i++) {
                                                                    if ($i != $Page) {
                                                                        echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
                                                                    } else {
                                                                        echo "<b> $i </b>";
                                                                    }
                                                                }
                                                                if ($Page != $Num_Pages) {
                                                                    echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
                                                                }
                                                                ?>
                                                        </td>
                                                    </tr>
                                                </table>
                                                </td>
                                                </tr>  
                                                <tr>
                                                    <td colspan="2">
                                                        <div><a href="../checklogout.php" onclick="return confirm('what do you want Exit')"> <img src="../images/logout.png" width="150px"></img></a></div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="footer" colspan="2">
                                                        Powered by Department Technology information Adinop
                                                    </td>
                                                </tr>
                                                </table>
                                                </body>
                                                </html>